home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / CPPAWARE.PAK / DBLIST.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  6KB  |  160 lines

  1. //--------------------------------------------------------
  2. // DBLIST.CPP
  3. // Copyrights (C) 1996 Borland International
  4. //--------------------------------------------------------
  5.  
  6. #include <vdbt/dbcontrl.h>
  7. #pragma hdrstop
  8. #include <vdbt/dblist.h>
  9. #include <stdio.h>
  10.  
  11. //--------------------------------------------------------
  12. // TDBListBox (VB3, subclassed from LISTBOX)
  13. //--------------------------------------------------------
  14. TDBListBox::TDBListBox( TWindow *parent, int id, LPCSTR title
  15.                       , int x, int y, int w, int h, TModule *module )
  16.   : TDBControl( parent, id, "TDBListBox", title, x, y, w, h, module )
  17.   , INIT_SOURCE( OnClick )
  18.   , INIT_SOURCE( OnDragDrop )
  19.   , INIT_SOURCE( OnDragOver )
  20.   , INIT_SOURCE( OnEndDrag )
  21.   , INIT_SOURCE( OnDblClick )
  22.   , INIT_SOURCE( OnDrawItem )
  23.   , INIT_SOURCE( OnEnter )
  24.   , INIT_SOURCE( OnExit )
  25.   , INIT_SOURCE( OnKeyDown )
  26.   , INIT_SOURCE( OnKeyPress )
  27.   , INIT_SOURCE( OnKeyUp )
  28.   , INIT_SOURCE( OnMeasureItem )
  29.   , INIT_SOURCE( OnMouseDown )
  30.   , INIT_SOURCE( OnMouseMove )
  31.   , INIT_SOURCE( OnMouseUp )
  32. {
  33. }
  34.  
  35. TDBListBox::TDBListBox( TWindow *parent, int resourceId, TModule *module )
  36.   : TDBControl( parent, resourceId, module )
  37.   , INIT_SOURCE( OnClick )
  38.   , INIT_SOURCE( OnDragDrop )
  39.   , INIT_SOURCE( OnDragOver )
  40.   , INIT_SOURCE( OnEndDrag )
  41.   , INIT_SOURCE( OnDblClick )
  42.   , INIT_SOURCE( OnDrawItem )
  43.   , INIT_SOURCE( OnEnter )
  44.   , INIT_SOURCE( OnExit )
  45.   , INIT_SOURCE( OnKeyDown )
  46.   , INIT_SOURCE( OnKeyPress )
  47.   , INIT_SOURCE( OnKeyUp )
  48.   , INIT_SOURCE( OnMeasureItem )
  49.   , INIT_SOURCE( OnMouseDown )
  50.   , INIT_SOURCE( OnMouseMove )
  51.   , INIT_SOURCE( OnMouseUp )
  52. {
  53. }
  54.  
  55. bool TDBListBox::Create()
  56. {
  57.   return TDBControl::Create();
  58. }
  59.  
  60. void TDBListBox::SetupWindow()
  61. {
  62.   TDBControl::SetupWindow();
  63. }
  64.  
  65. //--------------------------------------------------------
  66. // OWL response table.
  67. //--------------------------------------------------------
  68. DEFINE_DB_RESPONSE_TABLE1( TDBListBox, TDBControl )
  69.   EV_VBXEVENT_CLICK,
  70.   EV_VBXEVENT_DRAGOVER,
  71.   EV_VBXEVENT_DRAGDROP,
  72.   EV_VBXEVENT_ENDDRAG,
  73.   EV_VBXEVENT_DBLCLICK(    Event_TDBListBox_DblClick ),
  74.   EV_VBXEVENT_KEYDOWN(     Event_TDBListBox_KeyDown ),
  75.   EV_VBXEVENT_KEYPRESS(    Event_TDBListBox_KeyPress ),
  76.   EV_VBXEVENT_KEYUP(       Event_TDBListBox_KeyUp ),
  77.   EV_VBXEVENT_ENTER(       Event_TDBListBox_GotFocus ),
  78.   EV_VBXEVENT_EXIT(        Event_TDBListBox_LostFocus ),
  79.   EV_VBXEVENT_MOUSEDOWN(   Event_TDBListBox_MouseDown ),
  80.   EV_VBXEVENT_MOUSEMOVE(   Event_TDBListBox_MouseMove ),
  81.   EV_VBXEVENT_MOUSEUP(     Event_TDBListBox_MouseUp ),
  82.   EV_VBXEVENT_MEASUREITEM( Event_TDBListBox_MeasureItem ),
  83.   EV_VBXEVENT_DRAWITEM(    Event_TDBListBox_DrawItem ),
  84. END_RESPONSE_TABLE;
  85.  
  86.  
  87. //--------------------------------------------------------
  88. // Event Handlers
  89. //--------------------------------------------------------
  90. DEFINE_DB_EVENT( TDBListBox, OnClick,       TNotifyEvent,      Event_TDBListBox_Click );
  91. DEFINE_DB_EVENT( TDBListBox, OnDragDrop,    TDragEvent,        Event_TDBListBox_DragDrop );
  92. DEFINE_DB_EVENT( TDBListBox, OnDragOver,    TDragOverEvent,    Event_TDBListBox_DragOver );
  93. DEFINE_DB_EVENT( TDBListBox, OnEndDrag,     TDragEvent,        Event_TDBListBox_EndDrag );
  94. DEFINE_DB_EVENT( TDBListBox, OnDblClick,    TNotifyEvent,      Event_TDBListBox_DblClick );
  95. DEFINE_DB_EVENT( TDBListBox, OnDrawItem,    TDrawItemEvent,    Event_TDBListBox_DrawItem );
  96. DEFINE_DB_EVENT( TDBListBox, OnEnter,       TNotifyEvent,      Event_TDBListBox_GotFocus );
  97. DEFINE_DB_EVENT( TDBListBox, OnExit,        TNotifyEvent,      Event_TDBListBox_LostFocus );
  98. DEFINE_DB_EVENT( TDBListBox, OnKeyDown,     TKeyEvent,         Event_TDBListBox_KeyDown );
  99. DEFINE_DB_EVENT( TDBListBox, OnKeyPress,    TKeyPressEvent,    Event_TDBListBox_KeyPress );
  100. DEFINE_DB_EVENT( TDBListBox, OnKeyUp,       TKeyEvent,         Event_TDBListBox_KeyUp );
  101. DEFINE_DB_EVENT( TDBListBox, OnMeasureItem, TMeasureItemEvent, Event_TDBListBox_MeasureItem );
  102. DEFINE_DB_EVENT( TDBListBox, OnMouseDown,   TMouseEvent,       Event_TDBListBox_MouseDown );
  103. DEFINE_DB_EVENT( TDBListBox, OnMouseMove,   TMouseEvent,       Event_TDBListBox_MouseMove );
  104. DEFINE_DB_EVENT( TDBListBox, OnMouseUp,     TMouseEvent,       Event_TDBListBox_MouseUp );
  105.  
  106.  
  107. //--------------------------------------------------------
  108. // Getters & Setters
  109. //--------------------------------------------------------
  110. TDC *TDBListBox::prCanvas::Get()
  111. {
  112.   HDC Canvas = NULL;
  113.  
  114.   if( ! DBOUTER( Canvas )->GetVBXProperty( Prop_TDBComboBox_Canvas, &Canvas, -1 ) )
  115.     ThrowException( "Getting Canvas Failed!" );
  116.  
  117.   if( p )
  118.     delete p;
  119.  
  120.   if( (p = new TDC( Canvas )) == NULL )
  121.     ThrowException( "Memory Allocation Failed in TDBListBox::Canvas::Get()!" );
  122.  
  123.   return p;
  124. }
  125.  
  126.  
  127. // Methods
  128. SHORT TDBListBox::ItemAtPos( TPoint pt, bool Existing )
  129. {
  130.   if( Existing && ! GetClientRect().Contains( pt ) )
  131.     return -1;
  132.  
  133.   SHORT Index = SHORT( SendMessage( LB_GETTOPINDEX, 0, 0L ) );
  134.   try {
  135.   for( ; ! ItemRect( Index ).Contains( pt ) ; Index++ )
  136.     ;
  137.   } catch( TXOwl )
  138.   {
  139.     // Ignore the exeption throwen by ItemRect()
  140.   }
  141.  
  142.   return Index;
  143. }
  144.  
  145. TRect TDBListBox::ItemRect( SHORT Indx )
  146. {
  147.   TRect rc;
  148.  
  149.   if( LB_ERR == SendMessage( LB_GETITEMRECT, Indx, LPARAM( (TRect FAR*)&rc ) ) )
  150.   {
  151.     char Error[ 48 ];
  152.  
  153.     sprintf( Error, "TDBListBox::ItemRect(%d): Invalid Index", Indx );
  154.     TXOwl( Error ).Throw();
  155.   }
  156.  
  157.   return rc;
  158. }
  159.  
  160.